package com.niuxiaofa.newlaw.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Bean.TaskBean;
import com.niuxiaofa.newlaw.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import www.linwg.org.lib.LCardView;


public class MedalMissionAdapter extends RecyclerView.Adapter<MedalMissionAdapter.ViewHolder> {
    public List<TaskBean.DataDTO> listEntities;
    Onclick onclick;


    public MedalMissionAdapter(List<TaskBean.DataDTO> newsList, Onclick onclick) {
        this.onclick = onclick;
        this.listEntities = newsList;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_medalmission, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    String tags;

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        tags = "";
        TaskBean.DataDTO dataDTO = listEntities.get(i);

//        viewHolder.name.setText((String) listEntity.getUserName());
//
//        viewHolder.address.setText(listEntity.getAddress());
//
//        GlideUtils.loadUserImg(UIUtils.getContext(),listEntity.getHeader(),viewHolder.user_img);


        viewHolder.taskName.setText(dataDTO.getTaskName());
        viewHolder.completedNum.setText("(" + dataDTO.getCompletedNum() + "/" + dataDTO.getTaskCeiling() + ")");
        viewHolder.taskName.setText(dataDTO.getTaskName());
        viewHolder.taskDescribe.setText(dataDTO.getTaskDescribe());

        viewHolder.lcard.setOnClickListener(e->{

            onclick.onclick(i);
        });

        switch (dataDTO.getIsReceive()) {
            case "0":

                viewHolder.lcard.setCardBackgroundColor(Color.parseColor("#FFCCCCCC"));
                viewHolder.wanchen.setText("未完成");

                break;
            case "1":
                viewHolder.lcard.setCardBackgroundColor(Color.parseColor("#FFCCCCCC"));
                viewHolder.wanchen.setText("未完成");
                break;
            case "2":
                viewHolder.lcard.setCardBackgroundColor(Color.parseColor("#FFFFD518"));
                viewHolder.wanchen.setText("未完成");
                break;

        }


    }

    @Override
    public int getItemCount() {
        return listEntities.size();
    }

    public interface Onclick {

        void onclick(int c);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.taskName)
        TextView taskName;

        @BindView(R.id.completedNum)
        TextView completedNum;

        @BindView(R.id.taskDescribe)
        TextView taskDescribe;

        @BindView(R.id.wanchen)
        TextView wanchen;

        @BindView(R.id.lcard)
        LCardView lcard;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
